package tasky.ui;

import java.awt.Color;

/**
 * This Class helps generate Color objects for the UI to use to change colors of its Layout.
 * The Class accepts both Strings and Integers (Only if user provides 3 int)
 * 
 * @author Keith Lim Yong Ming A0097846J
 *
 */

public class ColorGenerator implements ColorGenInterface{

	private static final String ERROR_RED = "The Value for Red is out of bounds! Please enter a value from 0 to 255\n";
	private static final String ERROR_BLUE = "The Value for Blue is out of bounds! Please enter a value from 0 to 255\n";
	private static final String ERROR_GREEN = "The Value for Green is out of bounds! Please enter a value from 0 to 255\n";
	
	private static final int MIN_COLOR = 0;
	private static final int MAX_COLOR = 255;
	
	private static final String ERROR_INVALIDCOLOR = "Color does not exist in program! Use the Help Function (F1) to see what Colors we have!\n";
	
	private static final Color COLOR_DARKRED = new Color(185, 0, 5);
	private static final Color COLOR_DARKGREEN = new Color(25, 105, 15);
	private static final Color COLOR_DARKBLUE = new Color(5, 35, 115);
	private static final Color COLOR_PURPLE = new Color(115, 5, 115);
	private static final Color COLOR_BROWN = new Color(175, 115, 25);
	
	public ColorGenerator() {
		
	}
	
	public Color generateColor(int R, int B, int G) throws IllegalArgumentException{
		checkRedValidity(R);
		
		checkBlueValidity(B);
		
		checkGreenValidity(G);
		
		return new Color(R, B, G);
	}

	private void checkGreenValidity(int G) {
		if(G < MIN_COLOR || G > MAX_COLOR) {
			throw new IllegalArgumentException(ERROR_GREEN);
		}
	}

	private void checkBlueValidity(int B) {
		if(B < MIN_COLOR || B > MAX_COLOR) {
			throw new IllegalArgumentException(ERROR_BLUE);
		}
	}

	private void checkRedValidity(int R) {
		if(R < MIN_COLOR || R > MAX_COLOR) {
			throw new IllegalArgumentException(ERROR_RED);
		}
	}

	public Color generateColor(String color) throws Exception {
		color = color.toUpperCase();
		
		return retrieveColor(color);	
	}

	private Color retrieveColor(String color) {
		switch(color) {
			case "RED":	return Color.RED;
			case "BLUE": return Color.BLUE;
			case "GREEN": return Color.GREEN;
			case "PINK": return Color.PINK;
			case "ORANGE": return Color.ORANGE;
			case "BLACK": return Color.BLACK;
			case "GRAY": return Color.GRAY;
			case "YELLOW": return Color.YELLOW;
			case "CYAN": return Color.CYAN;
			case "WHITE": return Color.WHITE;
			case "DARK RED": return COLOR_DARKRED;
			case "DARK GREEN": return COLOR_DARKGREEN;
			case "DARK BLUE": return COLOR_DARKBLUE;
			case "PURPLE": return COLOR_PURPLE;
			case "BROWN": return COLOR_BROWN;
			default: throw new IllegalArgumentException(ERROR_INVALIDCOLOR);
		}
	}
}
